<?php
namespace Common\Behaviors;
defined('THINK_PATH') or exit();

class load_langBehavior extends \Think\Behavior {
    protected $options   =  array(
        'DEFAULT_LANG' => 'zh-cn', // 当前语言包
    );

    public function run(&$params){
        $lang = $group_lang = $module_lang = array();
        $lang_dir = LANG_PATH ;
        
        // 读取项目公共语言包
        if (is_file($lang_dir . '/zh-cn.php')) {
            $lang = include $lang_dir . '/zh-cn.php';
        }
      
        // 读取当前分组公共语言包
        if (defined('MODULE_NAME')) {
            $group_lang_file = APP_PATH. MODULE_NAME . '/Lang/zh-cn.php';
            if (is_file($group_lang_file)) {
                $group_lang = include $group_lang_file;
            }
        }
        // 读取当前模块语言包
        $module_lang_file = APP_PATH . MODULE_NAME . '/Lang/' . strtolower(CONTROLLER_NAME) . '.php';
        if (is_file($module_lang_file)) {
            $module_lang = include $module_lang_file;
        }
        $lang = array_merge($lang, $group_lang, $module_lang);

        $js_lang = isset($lang['js_lang']) ? $lang['js_lang'] : array();

        if(isset($lang['js_lang_' . strtolower(CONTROLLER_NAME) ]))
        {
        	$module_js_lang = $lang['js_lang_' . strtolower(CONTROLLER_NAME) ];
        }
        else 
        {
        	$module_js_lang = isset($lang['js_lang_' . CONTROLLER_NAME ]) ? $lang['js_lang_' . CONTROLLER_NAME] : array();
        }
  //      $module_js_lang = isset($lang['js_lang_' . strtolower(CONTROLLER_NAME) ]) ? $lang['js_lang_' . strtolower(CONTROLLER_NAME) ] : array();
        $lang['js_lang'] = array_merge($js_lang, $module_js_lang);
        L($lang);
    }
}